package com.eling.elcms.cater.webapp.controller;

import com.eling.elcms.cater.model.MealRecord;
import com.eling.elcms.cater.model.view.MealRecordDetailView;
import com.eling.elcms.cater.model.view.MealRecordView;
import com.eling.elcms.cater.model.view.OrderDishesView;
import com.eling.elcms.cater.service.IMealRecordService;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class MealRecordController extends BaseFormController{
	@Autowired
	private IMealRecordService mealRecordService;
	
	@RequestMapping("/api/cate/mealrecord/search*")
	@ResponseBody
	public List<MealRecord> sreach(@ModelAttribute SearchCondition sc,@ModelAttribute MealRecord mealRecord) {
		sc.setQueryCondition(mealRecord);
		return mealRecordService.search(sc); 
	}
	
	@RequestMapping("/api/cate/mealrecord/query")
    @ResponseBody
    public List<MealRecord> query(@ModelAttribute MealRecord cond){
    	return mealRecordService.query(cond); 
    }
	
	@RequestMapping("/api/cate/mealrecord/save")
    @ResponseBody
    public MealRecord save(@ModelAttribute@ModelFilling MealRecord mealRecord) {
		return mealRecordService.save(mealRecord);
    }
	
	@RequestMapping("/api/cate/mealrecord/{pkMealRecord}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkMealRecord) {
		mealRecordService.remove(pkMealRecord);
	    return new Msg("删除成功");
	}
	
	/**用餐消费记录    统计人员消费情况*/
	@RequestMapping("/api/cate/mealrecord/queryAll")
	@ResponseBody
	public List<MealRecordView> queryAll(@RequestParam(value="startDate")Date startDate,
										 @RequestParam(value="endDate")Date endDate){
		return mealRecordService.queryAll(startDate,endDate);
	}
	
	/** 用餐的详细记录*/
	@RequestMapping("/api/cate/mealrecord/queryoneperson")
	@ResponseBody
	public List<MealRecordDetailView> queryOnePerson(@RequestParam(value="startDate")Date startDate,
													@RequestParam(value="endDate")Date endDate,
													@RequestParam(value="pkConsumerAccount")Long pkConsumerAccount)	{
		return mealRecordService.queryOnePerson(startDate,endDate,pkConsumerAccount);
	}
	
	/**
	 * 菜品点餐保存
	 * @param view
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/cate/mealrecord/orderdishes")
    @ResponseBody
    public OrderDishesView orderDishes(@ModelAttribute OrderDishesView view) {
		return mealRecordService.orderDishes(view);
    }
	
}
